package org.foj.model {

import mx.collections.ArrayCollection;

public class GraphModel {
  public function GraphModel() {
  }

  public function groupCollectionBy(collection:ArrayCollection,
                                    field:String):ArrayCollection {
    var group:Array = new Array();

    for each(var item:Object in collection) {
      if (group[item[field]] == null) {
        group[item[field]] = 1;
      } else {
        group[item[field]]++;
      }
    }

    var result:ArrayCollection = new ArrayCollection();
    for (var key:String in group) {
      result.addItem({label: key, units: group[key]});
    }

    return result;
  }
}
}